//
//  AppDelegate.m
//  Lossen-UI-13-1
//
//  Created by lanou3g on 15/11/18.
//  Copyright (c) 2015年 张晓东. All rights reserved.
//

#import "AppDelegate.h"
#import "FirstViewController.h"
#import "ScondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"
#import "FifthViewController.h"
#import "SixViewController.h"
@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     //设置window
    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    //UITabBarController
    UITabBarController *rootTBC=[[UITabBarController alloc]init]; 
    //1.创建视图控制器
     FirstViewController *firstVC = [[FirstViewController alloc]init];
    //    first.title=@"firstVC";
//    //设置firstVC的Item的title
//    first.tabBarItem.title=@"First";
//    //2设置image
//    first.tabBarItem.image=[UIImage imageNamed:@"01-refresh"];
////    first.tabBarItem.selectedImage=[first.tabBarItem setImage:<#(UIImage *)#>]
//    //3.自定义item进行设置
//    UITabBarItem *firstItem=[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:101];
//    //添加标志(添加有信息来)
//    firstItem.badgeValue=@"1";
//    
//    //3.2替换原有的item属性
//    first.tabBarItem=firstItem;
   
    
    
    
    
    ScondViewController *scond=[[ScondViewController alloc]init];
//    scond.title=@"secendVC";
//    scond.tabBarItem.title=@"Secend";
//    scond.tabBarItem.image=[UIImage imageNamed:@"02-redo"];
    //自定义item设置图片(系统)
    UITabBarItem *scondItem=[[UITabBarItem alloc]initWithTitle:nil image:[UIImage imageNamed:@"02-redo"] tag:102];
    //替换原有属性的
    scond.tabBarItem=scondItem;
    
    
    
    
    
    ThirdViewController *third=[[ThirdViewController alloc]init];
//    third.title=@"thirdVC";
//    third.tabBarItem.title=@"Third";
    UITabBarItem *thirdItem=[[UITabBarItem alloc]initWithTitle:@"Third" image:[UIImage imageNamed:@"03-loopback"] selectedImage:[UIImage imageNamed:@"02-redo"]];
    third.tabBarItem=thirdItem;
    //设置有消息传过来时的提醒样式
    thirdItem.badgeValue=@"new";
    
    
    

    FourthViewController *fourth=[[FourthViewController alloc]init];
    fourth.tabBarItem.title=@"Fourth";
    fourth.tabBarItem.image=[UIImage imageNamed:@"04-squiggle"];
    fourth.tabBarItem.badgeValue=@"通知";
    
    
    
    FifthViewController *fifth=[[FifthViewController alloc]init];
    fifth.tabBarItem.title=@"Fifth";
    
    SixViewController *sixVC=[[SixViewController alloc]init];
    sixVC.tabBarItem.title=@"sixVC";
    //2.将创建好的视图控制器添加到tabBar管理的ViewControllers里
    //给first添加导航控制器
    UINavigationController *firstNC=[[UINavigationController alloc]initWithRootViewController:firstVC];
    //给
    UINavigationController *scendNC=[[UINavigationController alloc]initWithRootViewController:scond];
    UINavigationController *thirdNC=[[UINavigationController alloc]initWithRootViewController:third];
    UINavigationController *fourthNC=[[UINavigationController alloc]initWithRootViewController:fourth];
    UINavigationController *fifthNC=[[UINavigationController alloc]initWithRootViewController:fifth];
    UINavigationController *sixNC=[[UINavigationController alloc]initWithRootViewController:sixVC];
    
    rootTBC.viewControllers=[NSArray arrayWithObjects:firstNC,scendNC,thirdNC,fourthNC,fifthNC,sixNC,nil];
    //tabBar高度为49 navigation的高度为64 没有标签栏式44
    //设置tabBar被选中的颜色
    rootTBC.tabBar.tintColor=[UIColor purpleColor];
    //设置tabBar背景颜色
    rootTBC.tabBar.backgroundColor=[UIColor greenColor];
    //barStyle 风格 透明还是不透明
  //  rootTBC.tabBar.barStyle=UIBarStyleBlack;
    
    //注释:设置tabBarItem需要设置每个controller的tabBarItem
   //设置默认选中的Item(是tabBarController的属性);
    rootTBC.selectedIndex=2;
    //设置默认选中的controller
   // rootTBC.selectedViewController=first;(有此段话添加不上导航控制器)
    //设置改变所有的navigationBar和tabBar的颜色
    [[UINavigationBar appearance] setBackgroundColor:[UIColor redColor]];
    [[UITabBar appearance]setBackgroundColor:[UIColor orangeColor]];
    
    //设置代理UITabBarControllerDelegate
    rootTBC.delegate=self;
    //3.将rootTBC设置为跟视图控制器
   self.window.rootViewController=rootTBC;
    
    return YES;
}

#pragma mark---实现代理方法UITabBarControllerDelegate
//是否选中Viewcontroller方法(默认是选中)
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    //[ThirdViewController class]
    //viewController 是否和ThirdViewController是否同类
    if ([viewController isKindOfClass:[ThirdViewController class]]) {
        return NO;
    }
    return YES;
}
//已经选中Viewcontroller方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    //去掉通知消息的标志
    viewController.tabBarItem.badgeValue=nil;

}
//开始定制Viewcontroller方法
- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers {
    NSLog(@"*******%@",viewControllers);
}
//将要结束定义Viewcontroller方法
- (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
    NSLog(@"=======%@",viewControllers);
}
//已经结束定制Viewcontroller方法
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed{
    NSLog(@"-----%@",viewControllers);
}






- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
